package com.design.pattern.singleton;

/**
 * 普通的通过锁实现单例
 */
public class GeneralLockSingleton2 {
    /**
     * 统计实例化的次数
     */
    public static int count=0;
    /**
     * 构造方法私有化,防止直接new实例.
     */
    private GeneralLockSingleton2(){
        count++;
    }

    /**
     * 持有本类
     */
    private static GeneralLockSingleton2 instance;

    /**
     * 对外暴露的方法,返回单例实例(方法加锁)
     * @return 单例实例
     */
    public synchronized static GeneralLockSingleton2 getInstance(){
        if (null==instance){
            instance=new GeneralLockSingleton2();
        }
        return instance;
    }
}
